Track average and extreme heart rate and cadence for KML writer. Whitespace fixes.
authorrobertl <robertl>
Tue, 31 Oct 2006 16:53:32 +0000 (16:53 +0000)
committerrobertl <robertl>
Tue, 31 Oct 2006 16:53:32 +0000 (16:53 +0000)
defs.h
kml.c
route.c

diff --git a/defs.h b/defs.h
index 0bb9a2e87f46619584c260034da5538df60242f9..4236e79aac92c672b5f5a0748343ac9b4454366c 100644 (file)
--- a/defs.h
+++ b/defs.h
@@ -380,8 +380,13 @@ typedef struct {
        double  min_alt;
        double  max_spd;        /* Meters/sec */
        double  min_spd;        /* Meters/sec */
+       double  avg_hrt;        /* Avg Heartrate */
+       double  avg_cad;        /* Avg Cadence */
        time_t  start;          /* Min time */
        time_t  end;            /* Max time */
+       int     min_hrt;        /* Min Heartrate */
+       int     max_hrt;        /* Max Heartrate */
+       int     max_cad;        /* Max Cadence */
 } computed_trkdata;
 
 /*
diff --git a/kml.c b/kml.c
index 41fa5f491deb3ce0fdbc744e77f626f11857c300..a3851342ca8f46500cbeeb03360e1f3da06c8975 100644 (file)
--- a/kml.c
+++ b/kml.c
@@ -449,6 +449,22 @@ void kml_output_trkdescription(const route_head *header, computed_trkdata *td)
                double spd = fmt_speed(td->max_spd, &spd_units);
                TD2("<b>Max Speed</b> %.1f %s", spd, spd_units);
        }
+       if (td->avg_hrt) {
+               TD("<b>Avg Heart Rate</b> %.1f bpm", td->avg_hrt);
+       }
+       if (td->min_hrt < td->max_hrt) {
+               TD("<b>Min Heart Rate</b> %d bpm", td->min_hrt);
+       }
+       if (td->max_hrt) {
+               TD("<b>Max Heart Rate</b> %d bpm", td->max_hrt);
+       }
+       if (td->avg_cad) {
+               TD("<b>Avg Cadence</b> %.1f rpm", td->avg_cad);
+       }
+       if (td->max_cad) {
+               TD("<b>Max Cadence</b> %d rpm", td->max_cad);
+       }
+
        kml_write_xml(-1, "</table>]]>\n");
        kml_write_xml(-1, "</description>\n");
 
@@ -468,15 +484,15 @@ void kml_output_trkdescription(const route_head *header, computed_trkdata *td)
 static 
 void kml_output_header(const route_head *header, computed_trkdata*td)
 {
-        kml_write_xml(1,  "<Folder>\n");
+       kml_write_xml(1,  "<Folder>\n");
        kml_write_xmle("name", header->rte_name);
        kml_output_trkdescription(header, td);
 
-        if (export_points && header->rte_waypt_ct > 0) {
-          // Put the points in a subfolder
-          kml_write_xml(1,  "<Folder>\n");
-          kml_write_xml(0,  "<name>Points</name>\n");
-        }
+       if (export_points && header->rte_waypt_ct > 0) {
+              // Put the points in a subfolder
+              kml_write_xml(1,  "<Folder>\n");
+              kml_write_xml(0,  "<name>Points</name>\n");
+       }
 
         // Create an array for holding waypoint coordinates so that we
         // can produce a LineString at the end.
@@ -801,7 +817,7 @@ void kml_write(void)
         kml_write_xml(1, "<Style id=\"lineStyle\">\n");
         kml_write_xml(1, "<LineStyle>\n");
         kml_write_xml(0, "<color>%s</color>\n", opt_line_color);
-       kml_write_xml(0, "<width>%s</width>\n", opt_line_width);
+        kml_write_xml(0, "<width>%s</width>\n", opt_line_width);
         kml_write_xml(-1, "</LineStyle>\n");
         kml_write_xml(-1, "</Style>\n");
 
@@ -825,7 +841,7 @@ void kml_write(void)
        if (!realtime_positioning) {
                kml_write_xml(-1,  "</Folder>\n");
        }
-  
+
        // Output routes
        if (!realtime_positioning) {
                kml_write_xml(1,  "<Folder>\n");
diff --git a/route.c b/route.c
index 6760c40369b53b02f942e322b47951a9f381ec89..39130834f3a908b6e25d2bee22ad12f1dc92ba84 100644 (file)
--- a/route.c
+++ b/route.c
@@ -67,7 +67,7 @@ route_head_alloc(void)
        route_head *rte_head;
        rte_head = (route_head *) xcalloc(sizeof (*rte_head), 1);
        QUEUE_INIT(&rte_head->Q);
-        QUEUE_INIT(&rte_head->waypoint_list);
+       QUEUE_INIT(&rte_head->waypoint_list);
        return rte_head;
 }
 
@@ -93,7 +93,7 @@ any_route_free(route_head *rte)
 
 static void
 any_route_add_head( route_head *rte, queue *head ) {
-        ENQUEUE_TAIL( head, &rte->Q );
+       ENQUEUE_TAIL( head, &rte->Q );
 }
 
 static void
@@ -313,7 +313,7 @@ route_flush( queue *head )
 {
        queue *elem, *tmp;
        queue *q;
-        QUEUE_FOR_EACH(head, elem, tmp ) {
+       QUEUE_FOR_EACH(head, elem, tmp ) {
                q = dequeue(elem);
                any_route_free((route_head *)q);
        }
@@ -328,7 +328,7 @@ route_copy( int *dst_count, int *dst_wpt_count, queue **dst, queue *src ) {
                dst_wpt_count = &junk;
        }
        
-        if ( !*dst ) {
+       if ( !*dst ) {
                *dst = xcalloc( 1, sizeof( queue ));
                QUEUE_INIT( *dst );
                *dst_count = 0;
@@ -490,6 +490,10 @@ void track_recompute(const route_head *trk, computed_trkdata **trkdatap)
        waypoint *prev = &first;
        queue *elem, *tmp;
        int tkpt = 0;
+       int pts_hrt = 0;
+       double tot_hrt = 0.0;
+       int pts_cad = 0;
+       double tot_cad = 0.0;
        char tkptname[100];
        computed_trkdata *tdata = xcalloc(1, sizeof (computed_trkdata));
 
@@ -500,6 +504,7 @@ void track_recompute(const route_head *trk, computed_trkdata **trkdatap)
        first.latitude = 0;
        first.longitude = 0;
        first.creation_time = 0;
+       tdata->min_hrt =  9999;
        tdata->min_alt =  999999999;
        tdata->max_alt = -999999999;
 
@@ -548,6 +553,28 @@ void track_recompute(const route_head *trk, computed_trkdata **trkdatap)
                        tdata->max_alt = this->altitude;
                }
 
+               if (this->heartrate > 0) {
+                       pts_hrt++;
+                       tot_hrt += (float) this->heartrate;
+               }
+
+               if ((this->heartrate > 0) && (this->heartrate < tdata->min_hrt)) {
+                       tdata->min_hrt = (int) this->heartrate;
+               }
+
+               if ((this->heartrate > 0) && (this->heartrate > tdata->max_hrt)) {
+                       tdata->max_hrt = (int) this->heartrate;
+               }
+
+               if (this->cadence > 0) {
+                       pts_cad++;
+                       tot_cad += (float) this->cadence;
+               }
+
+               if ((this->cadence > 0) && (this->cadence > tdata->max_cad)) {
+                       tdata->max_cad = (int) this->cadence;
+               }
+
                if (this->creation_time && (this->creation_time < tdata->start)) {
                        tdata->start = this->creation_time;
                }
@@ -566,6 +593,15 @@ void track_recompute(const route_head *trk, computed_trkdata **trkdatap)
                }
                tkpt++;
        }
+
+       if (pts_hrt > 0) {
+               tdata->avg_hrt = tot_hrt / (float) pts_hrt;
+       }
+
+       if (pts_cad > 0) {
+               tdata->avg_cad = tot_cad / (float) pts_cad;
+       }
+
        if (!trkdatap) {
                xfree(tdata);
        }